package com.habdqn.listener.demo; /**
 * @author Administrator
 */

import com.habdqn.jspdemo.im.util.SystemConstant;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionBindingEvent;

/**
 * 用于监听用户HttpSession的开始和结束
 */
@WebListener
public class MyHttpSessionListener implements HttpSessionListener {


    @Override
    public void sessionCreated(HttpSessionEvent se) {


        //每当一个session被构建添加一个访客记录
        SystemConstant.ONLINE_NUMBER++;
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        //每当一个session被销毁，较少一个访客数量
        SystemConstant.ONLINE_NUMBER--;
    }
}
